package com.hulk.dryad.common.util;

import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author lqx
 */
public class PasswordEncoderFactoriesUtil {

    private static final PasswordEncoder PASSWORD_ENCODER = PasswordEncoderFactories.createDelegatingPasswordEncoder();

    /**
     * 密码加密
     * @param password 密码
     * @return 密文
     */
    public static String encode(String password){
        return PASSWORD_ENCODER.encode(password);
    }

    /**
     * 密码校验
     * @param password 明文密码
     * @param encodedPassword 密文密码
     * @return 校验结果
     */
    public static boolean matches(String password,String encodedPassword){
        return PASSWORD_ENCODER.matches(password,encodedPassword);
    }
}
